<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
		<link rel="stylesheet"  href="<%=request.getContextPath() %>/css/select2.css" />
		<link rel="stylesheet" href="<%=request.getContextPath() %>/css/uniform.css" />
  	
  </head>
  
  <body>
  	<input type="button" class="btn btn-mini btn-info" value="查看详情" id="show">
  	<input type="button" class="btn btn-mini btn-success" value="答卷提醒" id="answerMind">
  	<input type="button" class="btn btn-mini btn-primary" value="答卷个人统计" id="showUserSurStat" >
  	<input type="button" class="btn btn-mini btn-primary" value="导出" id="dcUserSurStat" >
  	
		<s:form  action="/survey/reback/surveyRebackList.html?doType=query" theme="simple">
    <div class="accordion-group widget-box">
      <div class="widget-title">
        <ul class="nav nav-tabs">
          <li class="active"><a data-toggle="tab" href="#tab2" id="tab_2">按个人</a></li>
          <li><a data-toggle="tab" href="#tab1" id="tab_1">按单位</a></li>
        </ul>
      </div>
      <div class="widget-content tab-content">
        <div id="tab1" class="tab-pane active">
		      <div class="accordion-heading">
		        <div class="widget-title"> 
		        	<a data-parent="#collapse-group" href="#collapseGOne" data-toggle="collapse" class="collapsed">
		         	<span class="icon"><i class="icon-search"></i></span>
		          	<h5>检索条件</h5>
		          	</a> 
		        </div>
		      </div>
		      <div class="accordion-body in collapse" id="collapseGOne" style="height: auto;">
		        <div class="form-horizontal">
		        	<div class="control-group">
		              <div class="search-controls">
		              		<label class="control-label2">单位名称</label>
		              		<input type="text" placeholder="Company Name" class="span2" id="companyName" >
		              		<label class="control-label2">问卷名称</label>
		              		<input type="text" placeholder="Survey Name" class="span2" id="surveyName" >
		              		<label class="control-label2">回收状态</label>
		              			<s:select list="#{1:'回收中',2:'回收结束'}" cssStyle="width:100px" name="surveyFlg" id="surveyFlg" listKey="key" listValue="value"  headerKey="" headerValue="">
		              			</s:select>
		              		<div class="button-search-right">
		              			<input type="button" class="btn btn-success" value="检  索" id="searchButton" onclick="searchResultTab1();">
		              		</div>
		              </div>
		            </div>
		        </div>
		      </div>
        </div>
        <div id="tab2" class="tab-pane">
		      <div class="accordion-heading">
		        <div class="widget-title"> 
		        	<a data-parent="#collapse-group" href="#collapseGOne" data-toggle="collapse" class="collapsed">
		         	<span class="icon"><i class="icon-search"></i></span>
		          	<h5>检索条件</h5>
		          	</a> 
		        </div>
		      </div>
		      <div class="accordion-body in collapse" id="collapseGOne" style="height: auto;">
		        <div class="form-horizontal">
		        	<div class="control-group">
		              <div class="search-controls">
		              		<label class="control-label2">姓名</label>
		              		<input type="text" placeholder="User Name" class="span2" id="userName" >
		              		<label class="control-label2">问卷名称</label>
		              		<input type="text" placeholder="Survey Name" class="span2" id="surveyNameUser" >
		              		<label class="control-label2">问卷状态</label>
		              			<s:select list="#{1:'回收中',2:'回收结束'}" cssStyle="width:100px" name="surveyFlgUser" id="surveyFlgUser" listKey="key" listValue="value"  headerKey="" headerValue="">
		              			</s:select>
		              		<div class="button-search-right">
		              			<input type="button" class="btn btn-success" value="检  索" id="searchButton" onclick="searchResultTab2();">
		              		</div>
		              </div>
		            </div>
		        </div>
		      </div>
        </div>
      </div>
    </div>
			</s:form>
    <hr />
    <div id="divTabGrid">
    	<table id="tabGrid"></table>
      <div id="pager"></div>
    </div>
    <div id="divTabGrid2">
    <table id="tabGrid2"></table>
    <div id="pager2"></div>
    </div> 
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/matrix.form_common.js"></script>		
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery/jqGridUtil.js"></script>
    <script type="text/javascript">
		var configReback1 = {
	          url:'<%=request.getContextPath() %>/survey/reback/surveyRebackList.html?doType=query&tab=1',
           	colModel:[
	              		{label:'send_id',name:"send_id",index:'send_id', key:true ,hidden:true},
	              		{label:'survey_flg',name:"survey_flg",index:'survey_flg', hidden:true},              		
                		{label:'单位名称',name:"company_name",index:'company_name'},
                		{label:'问卷名称',name:"survey_name",index:'survey_name'},
                		{label:'回收状态',name:"survey_flg_name",index:'survey_flg_name'},
                		{label:'被评估人数',name:"assess_user_counts",index:'assess_user_counts'},
                		{label:'发放问卷总数',name:"send_counts",index:'send_counts'},
                		{label:'回答数<br>[已提交]',name:"submit_counts",index:'submit_counts'},
                		{label:'保存数<br>[未提交]',name:"save_counts",index:'save_counts'},
                		{label:'未回答数',name:"unanswered_counts",index:'unanswered_counts'},
                		{label:'问卷回收率',name:"recycling_rate",index:'recycling_rate',width:'300px'}
           	],
           	table:"#tabGrid",
           	pager: "#pager",
           	sortname: 'insert_dt',
            sortorder: "desc",
            caption:"问卷回收信息列表"
      };
    	var configReback2 = {
               	url:'<%=request.getContextPath() %>/survey/reback/surveyRebackList.html?doType=query&tab=2',
               	colModel:[
               		{label:'send_id',name:"send_id",index:'send_id', key:true ,hidden:true},
              		{label:'survey_flg',name:"survey_flg",index:'survey_flg', hidden:true},
                 	{label:'姓名',name:"assess_user_nm",index:'assess_user_nm'},
              		{label:'单位名称',name:"company_name",index:'company_name'},
	            		{label:'问卷名称',name:"survey_name",index:'survey_name'},
	            		{label:'回收状态',name:"survey_flg_name",index:'survey_flg_name'},
	            		{label:'发放问卷总数',name:"send_counts",index:'send_counts'},
               		{label:'回答数<br>[已提交]',name:"submit_counts",index:'submit_counts'},
               		{label:'保存数<br>[未提交]',name:"save_counts",index:'save_counts'},
               		{label:'未回答数',name:"unanswered_counts",index:'unanswered_counts'},
               		{label:'问卷回收率',name:"recycling_rate",index:'recycling_rate',width:'300px'}
               	],
               	table:"#tabGrid2",
               	pager: "#pager2",
               	sortname: 'insert_dt',
                sortorder: "desc",
                caption:"问卷回收信息列表"
          };
	    var tab = "2";
	    jQuery(function(){

			//问卷发放结束
	    	jQuery("#show").bind("click",function(){
	    		    //选中的行
	    		    var id,tabGridNow;
	        		if(tab == "1"){
	        			tabGridNow = "tabGrid";
	        		}else{
	        			tabGridNow = "tabGrid2";
	        			
	        		}
	        		//选中的行
	            id = jQuery("#"+tabGridNow).jqGrid('getGridParam', 'selarrrow');
							if(id.length!=1){
								alert("请选择一条您要查看的记录!");
								return false;
							}

							var url="<%=request.getContextPath() %>/survey/reback/showSurveyReback.html"; 
							url+="?ids="+id.toString()+"&tab="+tab;
							showDialog('查看问卷信息',1130,390,url);
	    	});

			//问卷个人统计
	    	jQuery("#showUserSurStat").bind("click",function(){
	    		    //选中的行
	    		    var id,tabGridNow;
	        		if(tab == "1"){
	        			tabGridNow = "tabGrid";
	        		}else{
	        			tabGridNow = "tabGrid2";
	        		}
	        		//选中的行
	            id = jQuery("#"+tabGridNow).jqGrid('getGridParam', 'selarrrow');
							if(id.length!=1){
								alert("请选择一条您要查看的记录!");
								return false;
							}else{

								var url="<%=request.getContextPath() %>/survey/reback/showUserSurStat.html"; 
								url+="?ids="+id.toString()+"&tab="+tab;
								refMainContent(url);
							}
	    	});

			  //问卷个人统计[导出]
	    	jQuery("#dcUserSurStat").bind("click",function(){
	    		    //选中的行
	    		    var id,tabGridNow;
	        		if(tab == "1"){
	        			tabGridNow = "tabGrid";
	        		}else{
	        			tabGridNow = "tabGrid2";
	        		}
	        		//选中的行
	            id = jQuery("#"+tabGridNow).jqGrid('getGridParam', 'selarrrow');
							if(id.length!=1){
								alert("请选择一条您要导出的记录!");
								return false;
							}else{
								var url="<%=request.getContextPath() %>/survey/reback/dcUserSurStat.html"; 
								//var url="<%=request.getContextPath() %>/manage/downloadExcel/exportExcel.html"; 
								url+="?ids="+id.toString()+"&tab="+tab;
								subForm(url);
							}
	    	});

				//问卷提醒
	    	jQuery("#answerMind").bind("click",function(){
	    		    //选中的行
	    		    var id,tabGridNow;
	        		if(tab == "1"){
	        			tabGridNow = "tabGrid";
	        		}else{
	        			tabGridNow = "tabGrid2";
	        		}
	        		//选中的行
	            id = jQuery("#"+tabGridNow).jqGrid('getGridParam', 'selarrrow');
							if(id.length!=1){
								alert("请选择一条您要【答卷提醒】的记录!");
								return false;
							}else{

								for (var i = 0 ; i < id.length ; i++){
									var row = jQuery("#"+tabGridNow).jqGrid('getRowData', id[i]);
									if(row.unanswered_counts == "0" && row.save_counts =="0"){
										alert("该问卷没有需要提醒的人!");
										return false;
									}

									if(row.survey_flg !='1'){
										alert("请选择【回收中】的记录!");
										return false;
									}
								}								
								var url="<%=request.getContextPath() %>/survey/reback/answerMind.html"; 

								var _do = function(){
									jQuery.ajaxSetup({async:false});
									jQuery.post(url,{ids:id.toString(),tab:tab},function(data){
										alert(data.toString());
										refershGrid(tabGridNow);
									},'json');
									jQuery.ajaxSetup({async:true});
								}
								
								confirm('您确定要【问卷提醒】选择的记录吗？',_do);
							}
	    	});
	    	
	    	
		    // 初始化单位列表显示
		    
			  jQuery("#divTabGrid2").show();
			  jQuery("#pager2").show();
			  jQuery("#showUserSurStat").show();
			  jQuery("#dcUserSurStat").show();
			  
				jQuery("#divTabGrid").hide();
				jQuery("#pager").hide();
	    	jQuery.loadGrid(configReback2);
	    	
				//标签切换
	    	jQuery("#tab_1").bind("click",function(){
	    		tab = "1";
	    		jQuery("#tab_2").parent("li").removeClass('active');
				  jQuery("#tab2").hide();
	    		jQuery("#tab_1").parent("li").addClass('active');
				  jQuery("#tab1").show();
				  jQuery("#divTabGrid2").hide();
				  jQuery("#pager2").hide();
				  jQuery("#showUserSurStat").hide();
				  jQuery("#dcUserSurStat").hide();
					jQuery("#divTabGrid").show();
					jQuery("#pager").show();
		    	jQuery.loadGrid(configReback1);
		    	searchResultTab1();
		    	
	    	});

			  //标签切换
	    	jQuery("#tab_2").bind("click",function(){
		    	tab = "2";
	    		jQuery("#tab_1").parent("li").removeClass('active');
				  jQuery("#tab1").hide();
	    		jQuery("#tab_2").parent("li").addClass('active');
				  jQuery("#tab2").show();
				  jQuery("#divTabGrid2").show();
				  jQuery("#pager2").show();
				  jQuery("#showUserSurStat").show();
				  jQuery("#dcUserSurStat").show();
					jQuery("#divTabGrid").hide();
					jQuery("#pager").hide();
		    	jQuery.loadGrid(configReback2);
		    	searchResultTab2();
	    	});
	    });

	    /**
		    * 检索Tab1
		    * @param tabId
		    * @param jsonMap
		    */
	    function searchResultTab1() {
	    	var map = {};
	    	map["company_name"] = jQuery('#companyName').val();
	    	map["survey_name"] = jQuery('#surveyName').val();
	    	map["survey_flg"] = jQuery('#surveyFlg').val();
	    	search('tabGrid',map);
	    }
	    /**
		    * 检索Tab2
		    * @param tabId
		    * @param jsonMap
		    */
	    function searchResultTab2() {
	    	var map = {};
	    	map["assess_user_nm"] = jQuery('#userName').val();
	    	map["survey_name"] = jQuery('#surveyNameUser').val();
	    	map["survey_flg"] = jQuery('#surveyFlgUser').val();
	    	search('tabGrid2',map);
	    }
	    
	    function subForm(url) {
					if (url != null && url != '') {
						document.forms[0].action = url;
					}
					document.forms[0].submit();
			}
    </script>
  </body>
</html>
